﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using BOHVote.Core;

namespace BOHVote.DAL
{
    public class PrintContextProvide
    {
        Database db;
        public PrintContextProvide()
        {
            db = DatabaseFactory.CreateDatabase();
        }

        #region <<  SELECT   >>
        public DataSet dstPrintContext(string PrintContextID, string PrintTitle, string printContext,string status, string PrintType)
        {
            string strSQL = " SELECT PrintID,printTitle,printContext,STATUS,printType FROM ApplyPrintContext WHERE 1=1 ";
            if (!string.IsNullOrEmpty(PrintContextID))
            {
                strSQL += " AND PrintID =  " + PrintContextID;
            }
            if (!string.IsNullOrEmpty(PrintTitle))
            {
                strSQL += " AND printTitle = '" + PrintTitle + "'";
            }
            if (!string.IsNullOrEmpty(status))
            {
                strSQL += " AND status = '" + status + "'";
            }
            if (!string.IsNullOrEmpty(PrintType))
            {
                strSQL += " AND printType = '" + PrintType + "' ";
            }
            if (!string.IsNullOrEmpty(printContext))
            {
                strSQL += " AND printContext = '" + printContext + "' ";
            }

            DbCommand dbcommand = db.GetSqlStringCommand(strSQL);

            return Utility.ExecuteDataSet(db, dbcommand);
        }
        #endregion

        #region <<  UPDATE  >>
        public int UpdatePrintContext(string PrintContextID, string PrintTitle, string printContext,string status, string PrintType)
        {
            string strSQL = " UPDATE ApplyPrintContext SET [STATUS] = '" + status + "',printTitle = '" + PrintTitle + "',printContext = '" + printContext + "'  WHERE PrintID = " + PrintContextID ;
            DbCommand dbcommand = db.GetSqlStringCommand(strSQL);

            return Utility.ExecuteNonQuery(db, dbcommand);
        }
        #endregion


    }
}
